<template>
  <div class="card-container">
    <!-- 搜索区域 -->
    <div class="search-container">
      <span class="search-label">车牌号码：</span>
      <el-input v-model.trim="params.carNumber" clearable placeholder="请输入内容" class="search-main" />
      <span class="search-label">缴费状态：</span>
      <el-select v-model="params.paymentStatus">
        <el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
      <el-button type="primary" class="search-btn" @click="searchFn">查询</el-button>
    </div>
    <!-- 表格区域 -->
    <div v-auth-dir="`parking:payment:list`" class="table">
      <el-table style="width: 100%" :data="tableData">
        <el-table-column prop="id" label="序号">
          <template slot-scope="scope">
            {{ (params.page - 1) * params.pageSize + scope.$index + 1 }}
          </template></el-table-column>
        <el-table-column label="车牌号码" prop="carNumber" />
        <el-table-column label="收费类型" prop="chargeType" :formatter="formatterTypeFn" />
        <el-table-column label="停车总时长" prop="parkingTime" />
        <el-table-column label="缴纳费用(元)" prop="actualCharge" />
        <el-table-column label="缴纳状态" prop="paymentStatus" :formatter="formatterStatusFn" />
        <el-table-column label="缴纳方式" prop="paymentMethod" :formatter="formatterMethodFn" />
        <el-table-column label="缴纳时间" prop="paymentTime" fixed="right" width="180" />
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="page-container">
      <el-pagination
        layout="total, prev, pager, next"
        :total="total"
        @current-change="pageChange"
      />
    </div>
  </div>
</template>
<script>
import { getPayListAPI } from '@/apis/car'

export default {
  name: 'Pay',
  data() {
    return { // 状态列表
      statusList: [
        {
          value: null,
          label: '全部'
        },
        {
          value: 0,
          label: '待缴纳'
        },
        {
          value: 1,
          label: '已缴纳'
        }
      ], // 表格数据
      tableData: [],
      params: { // 请求参数
        page: 1,
        pageSize: 10,
        carNumber: '',
        paymentStatus: ''
      },
      total: 0
    }
  },
  created() {
    this.getList()
  },
  methods: {
    searchFn() {
      this.getList()
    },
    async getList() {
      // console.log(this.params)

      const res = await getPayListAPI(this.params)
      console.log(res)
      this.tableData = res.data.rows
      this.total = res.data.total
    },
    pageChange(page) { // 分页点击事件
      // 更改参数
      this.params.page = page
      // console.log(this.params.page)

      // 重新获取数据渲染
      this.getList()
    },
    formatterMethodFn(row) {
      // console.log(row)
      const obj = {
        'Alipay': '支付宝',
        'WeChat': '微信',
        'Cash': '线下',
        null: '无'
      }
      return obj[row.paymentMethod]
    },
    formatterTypeFn(row) {
      const obj = {
        'card': '月卡',
        'temp': '临时停车'
      }
      return obj[row.chargeType]
    },
    formatterStatusFn(row) {
      const obj = {
        0: '待缴纳',
        1: '已缴纳'
      }
      return obj[row.paymentStatus]
    }
  }
}
</script>
<style lang="scss" scoped>
.card-container {
  padding: 20px;
  background-color: #fff;
}

.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, .9);
  padding-bottom: 20px;

  .search-main {
    width: 220px;
    margin-right: 10px;
  }

  .search-btn {
    margin-left: 20px;
  }
}
.page-container {
  padding: 4px 0px;
  text-align: right;
}
</style>
